export const emojiList = [
  {
    content: "😊",
    rule: "[1]",
  },
  {
    content: "💔",
    rule: "[2]",
  },
  {
    content: "😠",
    rule: "[3]",
  },
  {
    content: "😭",
    rule: "[4]",
  },
  {
    content: "🐶",
    rule: "[5]",
  },
  {
    content: "🐱",
    rule: "[6]",
  },
  {
    content: "😄",
    rule: "[7]",
  },
  {
    content: "🥱",
    rule: "[8]",
  },
];

export function replaceStringToEmoji(str) {
  return str.replace(/\[\d+\]/g, ($) => {
    // 根据匹配内容查找
    const item = emojiList.find((v) => v.rule === $);
    // 查找到表情， 就替换
    if (item) return item.content;
    // 没找到啥也不做
    return $
  });
}

export function reaplceEmojiToString(str) {
  const emoji = emojiList.map(v => v.content).join("|")
  const reg = new RegExp(emoji, 'g')
  return str.replace(reg, ($) => {
      // 根据匹配内容查找
      const item = emojiList.find((v) => v.content === $);
      // 查找到表情， 就替换
      if (item) return item.rule;
      // 没找到啥也不做
      return ''
  })
}

